<template>
	<view class="add page c00">
		<view class="bgf7 p12">
			<view class="bgff px14 pb10">


				<view class="flex flexC  py12">
					<text class="flex1">券码</text>
					<input v-model="code" type="number" class=" aliR  py3" placeholder="请输入您的充值券码" />

				</view>


			</view>
			<view class="flex flexC flexJC py20">
				<view class="aliC py12 w-17 bgf6c r40" @click="doDui()">兑换</view>
			</view>


		</view>




	</view>
</template>

<script>
	export default {
		components: {},
		data() {
			return {

				code: '',
				amount: '',
				shop_name: ''

			};
		},
		onLoad(option) {


			this.getShopList();
		},

		onShow() {
			this.closePopup();
		},
		methods: {

			findpass() {
				uni.navigateTo({
					url: '../member/paypassword'
				})
			},

			onSelectShop(item) {
				this.selectShop = item;
				this.getCharge();
			},

			doDui() {


				if (this.code == '') {
					uni.showToast({
						title: "请输入兑换码",
						icon: "none"
					})
					return;
				}
				let param = {
					code: this.code,

				};
				let that = this;
				this.$api.codeChargeInfo(param).then(res => {
					console.info(JSON.stringify(res));
					if (res.code == 1) {

						uni.showModal({
							title: "兑换提示",
							content: "兑换店铺：" + res.data.shop_name + ",面额：" + res.data.amount,
							confirmText: "兑换",
							complete(res) {
								if (res.confirm) {
									that.doCodeCharge();
								}
							}

						})
					} else {
						uni.showToast({
							title: res.msg,
							icon: "none"
						})
					}
				})
			},

			doCodeCharge() {

				let param = {
					code: this.code
				}
				let that = this;
				this.$api.doCodeCharge(param).then(res => {

					if (res.code == 1) {

						uni.showModal({
							title: "兑换提示",
							content: "兑换成功",
							showCancel: false,
							confirmText: "确定",
							complete() {
								uni.navigateBack({
									delta: 1
								})
							}
						})

					} else {
						uni.showToast({
							title: res.msg,
							icon: "none"
						})
					}
				})
			},

			closePopup() {
				this.$refs.passwordPopup.close();
			},

			showPassword() {
				this.$refs.passwordPopup.open()
				this.$refs.KeyboarHid.open()
			},



			onInput(val) {
				this.password = val;
				console.log(this.password)
				if (this.password.length == 6) {
					this.save();
				}
			},


			save() {



				if (this.mobile == '') {

					uni.showToast({
						title: "请填写手机号",
						icon: 'none'
					})
					return;
				}

				if (this.amount == '') {

					uni.showToast({
						title: "请填写转赠金额",
						icon: 'none'
					})
					return;
				}

				let param = {
					shop_id: this.selectShop.id,
					mobile: this.mobile,
					amount: this.amount,
					password: this.password
				};
				let that = this;
				this.$api.sendMoney(param).then(res => {

					if (res.code == 1) {
						uni.showModal({
							title: "转赠提示",
							content: "转赠成功",
							showCancel: false,
							complete() {
								uni.navigateBack({
									delta: 1
								})
							}
						})
					} else if (res.code == -2) {
						uni.navigateTo({
							url: '../member/paypassword'
						})
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none'
						})
					}
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.add {
		.w48 {
			width: 96rpx;
			height: 96rpx;
		}

		.imgbox {
			width: 164rpx;
			height: 164rpx;
			background-color: #E8E8E8;
			position: relative;

			image {
				width: 100%;
				height: 100%;
			}

			.del {
				width: 36rpx;
				height: 36rpx;
				background: rgba(181, 180, 180, .8);
				position: absolute;
				top: -12rpx;
				right: -12rpx;
			}
		}
	}

	.pwdPopup {
		/deep/.uni-popup__wrapper {
			height: 80vh;
		}

		.inpbox {
			position: relative;

			.colse {
				position: absolute;
				top: 0;
				right: 0;
			}
		}
	}

	.popup-content2 {
		background: #FFFFFF;

		.popup-btn {
			width: 100%;
			height: 100rpx;
			line-height: 100rpx;
			text-align: center;
			border-bottom: 1px solid #f5f5f5;
			background: #FFFFFF;
		}

		.button {
			width: 100%;
			height: 100rpx;
			line-height: 100rpx;
			text-align: center;
			border-bottom: 1px solid #f5f5f5;
			background: #FFFFFF;
			font-size: 11pt;
		}

		button::after {
			border: none;
		}

		.pt20 {
			border-bottom: 20rpx solid #f5f5f5;
		}


	}
</style>